home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3610 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: news.walrus.com!news
  2. From: fjordao@walrus.com (Felipe Jordao)
  3. Newsgroups: comp.lang.c++
  4. Subject: [Q] equivalent or better strtok() in C++?
  5. Date: Thu, 25 Jan 1996 02:13:07 GMT
  6. Organization: HAC
  7. Message-ID: <4e6p1m$anc@walrus2.walrus.com>
  8. NNTP-Posting-Host: p22.ts1.walrus.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi,
  12.  
  13. I have been trying to use strtok() to get tokens from a delimited
  14. string but it only recognizes tokens with one or more characters.  (I
  15. know this is how the function is defined).
  16.  
  17. However...
  18.  
  19. if I have a string like this:
  20.  
  21. "one.two.three..five."
  22.  
  23. then using 
  24.  foo[0] = strtok(somebuffer, ".");
  25.  foo[1] = strtok(NULL, ".");        /// subsequent strtoks would be in a loop
  26.  foo[2] = strtok(NULL, ".");
  27.  .
  28.  .
  29.  foo[4] = strtok(NULL, ".");
  30.  
  31. will give me     ...     as opposed to 
  32.  
  33.  foo[0] = one             foo[0] = one
  34.  foo[1] = two             foo[1] = two
  35.  foo[2] = three           foo[2] = three
  36.  foo[3] = five            foo[3] = <something> or maybe even NULL
  37.  foo[4] = NULL            foo[4] = five
  38.  
  39.  
  40. I would like to get the results on the right by using either strtok()
  41. or some other better iostream function (if there is any).  I know I
  42. can resort to reading the line character by character, but that's too
  43. inefficient when the line is very long.
  44.  
  45. any suggestions?
  46. thanks
  47. Felipe
  48.  
  49.